import { RecommendReply, RecommendStatus, RecommendUpdates } from '@/models/recommend'
import { PageParams, Pagination, Status } from '@/models/sys'
import { http, httpSteam } from '@/utils/http'

/** 列表 */
export const getRecommendReplyList = (params: PageParams & { status: RecommendStatus }) => {
  return http.get<Pagination<RecommendReply>>(
    '/library-client/api/wxwork/recommend-reply/list',
    params,
  )
}

/** 检查最新数据 */
export const checkLatestRecommendReply = (params?: { start_id: number; latest_id: number }) => {
  return http.get<RecommendUpdates>('/library-client/api/wxwork/recommend-reply/latest', params)
}

/** 编辑内容 */
export const updateRecommendReply = (params: { id: number; reply_content: string }) => {
  return http.post('/library-client/api/wxwork/recommend-reply/edit', params)
}

/** 重新生成 */
export const regenerateSubmit = (params: { id: number; protocol: string }) => {
  return http.post<{ content: string }>(
    '/library-client/api/wxwork/recommend-reply/regenerate',
    params,
  )
}

/** 重新生成 */
export const regenerateRecommendReply = (
  params: { id: number },
  onChange: (msg: string) => void,
  onDone: () => void,
) => {
  return httpSteam.post(
    '/library-client/api/wxwork/recommend-reply/regenerate',
    params,
    {},
    (res) => {
      if (res) {
        onChange(res.choices[0].delta.content)
      } else {
        onDone()
      }
    },
  )
}

/** 点踩 */
export const dislikeRecommendReply = (params: { id: number; is_bad: Status }) => {
  return http.post('/library-client/api/wxwork/recommend-reply/bad', params)
}

/** 立即发送 */
export const sendRecommendReply = (params: { id: number; reply_content: string }) => {
  return http.post('/library-client/api/wxwork/recommend-reply/send', params)
}
